@extends('admin::layouts.master')
@section('content')
    <div class="card" id="app">
        <div class="card-header">分类管理管理</div>
        <ul role="tablist" class="nav nav-tabs">
            <li class="nav-item"><a href="/buy/catego" class="nav-link">分类管理列表</a></li>
            <li class="nav-item"><a href="#" class="nav-link active">修改分类管理</a></li>
        </ul>
        <form action="/buy/catego/{{$catego['id']}}" method="post">
            <div class="card-body card-body-contrast">
                @csrf @method('PUT')
                <div class="form-group row">
    <label for="name" class="col-12 col-sm-3 col-form-label text-md-right">分类名称</label>
    <div class="col-12 col-md-9">
        <input id="name" name="name" type="text"
               value="{{ $catego['name']??old('name') }}"
               class="form-control form-control-sm form-control{{ $errors->has('name') ? ' is-invalid' : '' }}">
        @if ($errors->has('name'))
            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('name') }}</strong>
            </span>
        @endif
    </div>
</div>


                <div class="form-group row">
                    <label for="pid" class="col-12 col-sm-3 col-form-label text-md-right">父级分类</label>
                    <div class="col-12 col-md-9">
                        <select class="form-control" id="category" name="pid">
                            <option value="0">顶级分类</option>
                            @foreach($cates as $v)
                                @if($v['_level'] < 3)

                                    <option value="{{$v['id']}}" pid="{{$v['pid']}}" {{$v['_disabled']}} @if($catego['pid']==$v['id']) selected  @endif>{{$v['name']}}</option>

                                @endif
                            @endforeach

                        </select>
                        @if ($errors->has('pid'))
                            <span class="invalid-feedback" role="alert">
                <strong>{{ $errors->first('pid') }}</strong>
            </span>
                        @endif
                    </div>
                </div>


                <div class="form-group row pt-1 pb-1" id="attrs">
                    <label class="col-12 col-sm-3 col-form-label text-sm-right">可用属性</label>
                    <div class="col-12 col-sm-8 col-lg-6 form-check mt-2">

                        @foreach($cg as $v)
                            <label class="custom-control custom-checkbox custom-control-inline">
                                <input type="checkbox" name="attrs[]" value="{{$v['id']}}" @if(in_array($v['id'],$attrid)) checked  @endif class="custom-control-input">
                                <span class="custom-control-label" style="padding-left: 30px">{{$v['name']}}</span>
                            </label>
                        @endforeach

                    </div>
                </div>
            </div>

            <div class="card-footer text-muted">
                <button class="btn btn-primary offset-sm-2">保存更新</button>
            </div>
        </form>
    </div>
@endsection
@section('script')
    <script>

            if ('{{$show}}' == 'show'){
                $('#attrs').show()
            } else {
                $('#attrs').hide()
            }

            $('#category').change(function () {
                // alert(123);
                //获取到当前被点击的option的值
                var pid = $(this).find('option:selected').attr('pid');
                if (pid != 0) {
                    $('#attrs').show();
                } else {
                    $('#attrs').hide();
                }
            })
    </script>
@endsection